﻿using KPI.Api;
using KPI.Data;
using KPI.Entity;
using System;
using System.Windows;
using System.Windows.Controls;
using TYBase;

namespace KPIClient.Views
{
    /// <summary>
    /// ViewCreateQuestionNaire.xaml 的交互逻辑
    /// </summary>
    public partial class ViewCreateQuestionNaire : UserControl
    {
        #region Event_AfterCreateQuestionNaire
        public event Action<string> Event_AfterCreateQuestionNaire;
        private void FireEvent_AfterCreateQuestionNaire(string data)
        {
            Event_AfterCreateQuestionNaire?.Invoke(data);
        }
        #endregion

        ViewCreateQuestionNaireModel vm = new ViewCreateQuestionNaireModel();
        public ViewCreateQuestionNaire()
        {
            InitializeComponent();
            this.DataContext = vm;
        }

        private void BtnClick_CreateQuestionNaire(object sender, RoutedEventArgs e)
        {
            string name = vm.Name;
            ExamRecordInfo dto = new ExamRecordInfo()
            {


                examType = (int)EnumExamType.Naire,
                creatorCode = KPIData.user.userId,
                title = name,

            };
            var rData = QuesionNaireApi.CreateQuestionNare(dto);

            if (rData == null)
            {
                MessageBox.Show("数据异常,请检查日志!");
                return;
            }
            if (rData.code != 0)
            {
                MessageBox.Show("数据异常,code:" + rData.code + ":msg:" + rData.msg);
                return;
            }

            if (rData.data.Null())
            {
                MessageBox.Show(messageBoxText: "系统异常! 返回数据没有id");
                return;
            }
            FireEvent_AfterCreateQuestionNaire(rData.data);
        }
    }
}
